#ifndef __COTASIA_H__
#define __COTASIA_H__

#include <sys/types.h>

#define ASSERT(e)       do {if (! (e)) {::abort();}} while (0)
#define ARRAY_COUNT(a)  (sizeof(a) / sizeof(a[0]))


namespace cotasia {
class Object;
template <typename T> class SmartPointer;
template <typename base, typename derived> class InheritanceShip;
}


namespace cotasia {
template <typename base, typename derived> class InheritanceShip
{
public:
    /* 检测继承关系，真表示继承关系成立 */
    bool operator ()(void) const
    {
        return (sizeof(check(static_cast<base const*>(0))) == \
            sizeof(check(static_cast<derived const*>(0))));
    }

    operator bool(void) const
    {
        return (*this)();
    }

private:
    /* type为无用模板形参，因为嵌套类模板只能偏特化 */
    template <int n, typename type=void> class __size_box__
    {
    private:
        __size_box__<n-1, type> __box1__;
        __size_box__<n-1, type> __box2__;
    };

    template <typename type> class __size_box__<0, type>
    {
    private:
        char __c__;
    };

private:
    __size_box__<0> check(base const*) const;
    __size_box__<1> check(...) const;

};

class Object {
template <typename TYPE> friend class cotasia::SmartPointer;
public:
    // static void *operator new(size_t size);
    // static void operator delete(void *p);

    virtual ~Object(void) {}
};
} // end of namespace cotasia
#endif // __COTASIA_H__
